<template>
  <div class="app-container">
    <el-table v-loading="listLoading" :data="list" height="400" style="width: 100%;margin-top:10px; overflow:auto" border>
      <el-table-column label="序号" type="index" header-align="center" align="center" width="60" />
      <el-table-column header-align="center" align="left" label="文档名" show-overflow-tooltip min-width="520px">
        <template slot-scope="scope">
          <span>{{ scope.row.originalName }}</span>
        </template>
      </el-table-column>
      <el-table-column header-align="center" align="left" label="文档类型" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.suffix }}</span>
        </template>
      </el-table-column>
      <el-table-column header-align="center" align="left" label="记录类型" width="150px">
        <template slot-scope="scope">
          <span>{{ getDicName(scope.row.flag,'CDS_RECORDS_TYPE') }}</span>
        </template>
      </el-table-column>
      <el-table-column header-align="center" align="left" label="目录" width="240">
        <template slot-scope="scope">
          <span>{{ scope.row.xftName }}</span>
        </template>
      </el-table-column>
      <el-table-column header-align="center" align="right" label="版本号" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.sortNum }}</span>
        </template>
      </el-table-column>
      <el-table-column header-align="center" align="left" label="创建人员" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.createuserName }}</span>
        </template>
      </el-table-column>
      <el-table-column header-align="center" align="right" label="创建时间" width="180">
        <template slot-scope="scope">
          {{ scope.row.createtimeTi }}
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>

import { getRecords } from '@/api/projectFile'
import { getDictListByCode } from '@/api/dict'

export default {
  inject: ['getList'],
  props: { // 第二种方式
    history: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      listLoading: false,
      list: [],
      spTypes: []
    }
  },
  created() {
    this.loadList()
    this.getDictEntry('CDS_RECORDS_TYPE')
  },
  methods: {
    loadList() { // 加载列表
      this.list = []

      getRecords({ batchCode: this.history }).then(response => {
        const { data } = response

        this.list = data
        this.listLoading = false
      }).catch(response => {
        this.listLoading = false
      })
    },
    getDictEntry(code) {
      getDictListByCode(code).then(response => {
        if (code === 'CDS_RECORDS_TYPE') {
          this.spTypes = response.data
        }
      })
    },
    getDicName(code, flag) {
      var dict = []
      if (flag === 'CDS_RECORDS_TYPE') {
        dict = this.spTypes
        for (var i in dict) {
          if (dict[i].code === code) {
            return dict[i].name
          }
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
